"use strict";

var setInter = void 0;
var passwordKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDYqxNMjTRQIvf9JylgBaCOwdAvE3XwWJownq8K8iy5FDMaC7wYHmbw6s+B66TcOYLZFy10mUYxkV+J+epmpnIxMSdXYZ7sU2pqbB9tZmtdkiy4YLoXQUirwaZsEJSApQF/P9StfqAralyG2wguBYyujF8EdV4Kbrb5vD+QTxcwxQIDAQAB";

$(function () {
    toastr.options = {
        closeButton: false,
        debug: false,
        progressBar: true,
        positionClass: "toast-top-center",
        onclick: null,
        showDuration: "300",
        hideDuration: "1000",
        timeOut: "2000",
        extendedTimeOut: "1000",
        showEasing: "swing",
        hideEasing: "linear",
        showMethod: "fadeIn",
        hideMethod: "fadeOut"
    };

    //注册提交
    $("#submit").click(function () {
        var params = {
            phone: $(".userPhone").val(),
            code: $(".code").val(),
            password: $(".password").val()
        };

        if (!/^1[3456789]\d{9}$/.test(params.phone)) {
            toastr.info("手机号码有误，请重填");
            return false;
        }
        if (!params.code) {
            return toastr.info('请输入验证码');
        }
        if (!params.password) {
            return toastr.info('请输入密码');
        }
        if (!$(".confirm_password").val()) {
            return toastr.info('请确认密码');
        }
        if (params.password !== $(".confirm_password").val()) {
            return toastr.info('两次输入的密码不一致');
        }

        var encrypt = new JSEncrypt();
        encrypt.setPublicKey(passwordKey);
        var password_Encry = encrypt.encrypt(params.password);
        params.password = password_Encry;

        $.server(params, '/iagent/v1/forgetPass').then(function (res) {
            console.log("注册成功！", res);
            location.href = "login.html";
        });
    });

    //获取验证码
    $(".reset-code").click(function () {
        var phone = $(".userPhone").val();
        if (!/^1[3456789]\d{9}$/.test(phone)) {
            toastr.info("手机号码有误，请重填");
            return false;
        }
        $.server({ phone: phone, type: 1 }, '/iagent/v1/smsCode').then(function (res) {
            console.log(res);
            toastr.info('验证码发送成功');
        });
        clearInterval(setInter);
        var time = 60;
        setInter = setInterval(function () {
            $(".reset-code").attr("disabled");
            $(".reset-code").addClass("disabled");
            $(".reset-code").text(time + "s");
            time--;
            if (time == 0) {
                clearInterval(setInter);
                $(".reset-code").removeAttr("disabled");
                $(".reset-code").removeClass("disabled");
                $(".reset-code").text("获取验证码");
            }
        }, 1000);
    });
});